<?php
/**
 * Created by PhpStorm.
 * User: bolle
 * Date: 24.12.15
 * Time: 11:31
 */

namespace tbollmeier\alteraparser\syntaxgraph;


class MatcherVertex extends Vertex
{
    private $chars;
    private $negated;

    public function __construct($chars = [], $negated = false)
    {
        parent::__construct(VertexCategory::MATCHER);

        $this->chars = $chars;
        $this->negated = $negated;
    }

    public function matches($matchChar)
    {
        $found = false;
        foreach ($this->chars as $ch) {
            if ($ch === $matchChar) {
                $found = true;
                break;
            }
        }

        return !$this->negated ? $found : !$found;
    }

    public function negate($neg = true)
    {
        $this->negated = $neg;
        return $this;
    }

    public function add($ch)
    {
        array_push($this->chars, $ch);
        return $this;
    }

    protected function onCopy($original)
    {
        parent::onCopy($original);
        $this->chars = $original->chars;
        $this->negated = $original->negated;
    }

}